package ar.edu.itba.bundundu.dao;

import java.util.List;

import javax.jdo.PersistenceManager;

import ar.edu.itba.bundundu.domain.UserIds;

public class UserDao {
	

	public static void save(UserIds user){
		PersistenceManager pm = PMF.get().getPersistenceManager();
			
        try {
            pm.makePersistent(user);
        }catch(Exception e){
        	pm.close();
        }finally {
            pm.close();
        }
        
	}
	
	public static UserIds getUser(long uid){
		UserIds user = null;
		PersistenceManager pm = PMF.get().getPersistenceManager();
		String query = "select from " + UserIds.class.getName() + " where uid == " + uid;
	    List<UserIds> users = (List<UserIds>)pm.newQuery(query).execute();
	    if (!users.isEmpty()) {
	    	user= users.get(0);
	    	
	    }
		return user;
	}
	
	public static UserIds getUserByEmail(String email){
	  UserIds user = null;
	  PersistenceManager pm = PMF.get().getPersistenceManager();
    String query = "select from " + UserIds.class.getName() + " where email == '" + email+"'";
      List<UserIds> users = (List<UserIds>)pm.newQuery(query).execute();
      if (!users.isEmpty()) {
        user= users.get(0);
      }
    return user;
	}

}
